package com.example.monitorapp.activity

import android.content.Intent
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.baselib.activity.BaseViewModelActivity
import com.example.baselib.constants.ARConstants
import com.example.baselib.constants.MyConstants
import com.example.baselib.dialog.MsgDialog
import com.example.monitorapp.BtnData
import com.example.monitorapp.MainBtnAdapter
import com.example.monitorapp.R
import com.example.monitorapp.viewmodel.MainViewModel
import kotlinx.android.synthetic.main.activity_main.*

// 在支持路由的页面上添加注解(必选)
// 这里的路径需要注意的是至少需要有两级，/xx/xx
@Route(path = ARConstants.APP_MAIN)
class MainActivity : BaseViewModelActivity<MainViewModel>() {
    lateinit var btnAdapter: MainBtnAdapter
    private val msgDialog by lazy { MsgDialog("系统正在开发中....") }
    override fun providerVMClass(): Class<MainViewModel>? = MainViewModel::class.java
    override fun layoutResId(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
        setShowToolbar(false)
        main_head_img.setOnClickListener {
            startActivity(
                Intent(
                    this,
                    UserInfoActivity::class.java
                )
            )
        }
        main_name_txt.text = MyConstants.userData.username
        main_post_txt.text = MyConstants.userData.post

    }

    override fun initData() {
        btnAdapter = MainBtnAdapter(R.layout.main_btn_itme, viewModel.getBtnData())
        btnAdapter.setOnItemClickListener { adapter, view, position ->
            if (!isFastClick()){
                val btnData = adapter.getItem(position) as BtnData
                when (btnData.btnId) {
                    MyConstants.SAFE -> {
                        if (MyConstants.userData.usertype==1){
                            ARouter.getInstance().build(ARConstants.APP_SAFE)
                                .navigation()
                        }else{
                            ARouter.getInstance().build(ARConstants.APP_SAFE_NICK)
                                .navigation()
                        }

                    }
                    MyConstants.PERSON -> {
                        if (MyConstants.userData.usertype==1){
                            ARouter.getInstance().build(ARConstants.APP_RYDW)
                                .navigation()
                        }else{
                            ARouter.getInstance().build(ARConstants.APP_RYDW_NICK)
                                .navigation()
                        }

                    }
                    MyConstants.PRODUCT -> {
                        msgDialog.show(supportFragmentManager, "MainBtnDialog")
                    }
                    MyConstants.VIDEO -> {
                        ARouter.getInstance().build(ARConstants.APP_VIDEO)
                            .navigation()
                    }
                    MyConstants.RESCUE -> {
                        msgDialog.show(supportFragmentManager, "MainBtnDialog")
                    }
                    MyConstants.DEVICE -> {
                        msgDialog.show(supportFragmentManager, "MainBtnDialog")
                    }
                    MyConstants.WATER -> {
                        msgDialog.show(supportFragmentManager, "MainBtnDialog")
                    }
                    MyConstants.KZDYL -> {
                        msgDialog.show(supportFragmentManager, "MainBtnDialog")
                    }
                    else -> {}
                }
            }
        }
        val gridLayoutManager = GridLayoutManager(this, 4)
        main_btn_rcv.layoutManager=gridLayoutManager
        main_btn_rcv.adapter = btnAdapter

    }


}
